package org.linitly.util;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;

/**
 * @author: linxiunan
 * @date: 2021/5/31 10:20
 * @descrption:
 */
public class FileCopyUtil {

    public static void copyFile(File sourceFile, File destFilePathDir) throws IOException {
        String newFilePath = destFilePathDir.getPath() + "/" + sourceFile.getName();
        File newFile = new File(newFilePath);
        if (newFile.exists()) return;
        Files.copy(sourceFile.toPath(), newFile.toPath());
    }

    public static File copyDir(File sourceDir, File destParentDir) {
        String sourceDirName = sourceDir.getName();
        String destDirPath = destParentDir.getPath() + "/" + sourceDirName;
        File destDir = new File(destDirPath);
        if (destDir.exists()) return destDir;
        boolean mkSuccess = destDir.mkdir();
        if (!mkSuccess) {
            System.out.println("mkdir error, the path is" + destDirPath);
            System.exit(-1);
        }
        return destDir;
    }

    public static File createProjectDir(String projectName, File destParentDir) {
        String destProjectPath = destParentDir.getPath() + "/" + projectName;
        File destDir = new File(destProjectPath);
        if (destDir.exists()) return destDir;
        boolean mkSuccess = destDir.mkdir();
        if (!mkSuccess) {
            System.out.println("mkdir error, the path is" + destProjectPath);
            System.exit(-1);
        }
        return destDir;
    }

    public static void copyJavaFile(File sourceFile, File destFilePathDir) throws IOException {

    }
}
